package com.peas.platform.common.core.configuration;

import com.alibaba.cloud.nacos.ConditionalOnNacosDiscoveryEnabled;
import com.alibaba.cloud.nacos.registry.NacosRegistration;
import com.alibaba.cloud.nacos.registry.NacosServiceRegistry;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
@ConditionalOnNacosDiscoveryEnabled
@Slf4j
public class NacosServiceDelayRegistry implements CommandLineRunner {

    @Value("${server.port}")
    private Integer serverPort;

    @Resource
    private NacosRegistration registration;
    @Resource
    private NacosServiceRegistry nacosServiceRegistry;

    @Override
    public void run(String... args) {
        registration.setPort(serverPort);
        nacosServiceRegistry.register(registration);
        log.info("项目加载nacos完成");
    }

}
